<?php
namespace app\front\controller;

use app\front\logic\ApiLogic;
use app\front\logic\DictLogic;
use app\front\logic\ChannelCountryLogic;

class Item extends Base{
	//获取洲
	function getContinentList(){
		$data = DictLogic::init()->getList($this->lang, 'continent');
		return ApiLogic::return($this->lang, 0,'', $data);
	}
	//获取洲+国家
    function getCountryList(){
    	$data = ChannelCountryLogic::init()->getList($this->lang);
    	return ApiLogic::return($this->lang, 0,'', $data);
    }
    //获取国家对应的项目列表
    function getItemList(){
        $params = [];
        $params['country_id'] = $this->country_id;
        $params['channel_id'] = $this->channel_id;
        $params['server_id'] = $this->server_id;
        $params['lang'] = $this->lang;
        $params['country_code'] = $this->country_code;
        $params['server_code'] = $this->server_code;
        $params['item_exchange_rate'] = $this->item_exchange_rate;
        $params['item_base_rate'] = $this->item_base_rate;
        $params['is_ok'] = $this->is_ok;
        $params['currency_symbol'] = $this->currency_symbol;
    	$data = ChannelCountryLogic::init()->getServerList($params, $this->baseInfo);
        // sys_log(json_encode($data),'guojia.log');
        if(!$data){
            return ApiLogic::return($this->lang, '100002');
        }
    	return ApiLogic::return($this->lang, 0,'', $data);
    }

    //获取服务对应的详细信息
    function getServerInfo(){
        $params = [];
        $params['country_id']   = $this->country_id;
        $params['channel_id']   = $this->channel_id;
        $params['server_id']    = $this->server_id;
        $params['lang']         = $this->lang;
        $params['country_code'] = $this->country_code;
        $params['server_code']  = $this->server_code;
        $params['item_exchange_rate'] = $this->item_exchange_rate;
        $params['item_base_rate']   = $this->item_base_rate;
        $params['is_ok']            = $this->is_ok;
        $params['currency_symbol']  = $this->currency_symbol;
        $params['exchange_rate']    = $this->exchange_rate;
        $params['total_amount']     = $this->total_amount;
        $rs = ChannelCountryLogic::init()->getServerInfo($params, $this->baseInfo, $this->member_info);
        if($rs['code']!=0){
            return ApiLogic::return($this->lang, $rs['code']);
        }
        return ApiLogic::return($this->lang, 0, '', $rs['data']);
    }

    //获取手机号码
    function getNumber(){
        $order_sn = input('order_sn', '');
        $rs = ChannelCountryLogic::init()->getNumber($order_sn, $this->member_id);
        if($rs['code']!=0){
            return ApiLogic::return($this->lang, $rs['code'],'',$rs['data']);
        }
        return ApiLogic::return($this->lang, 0, '', $rs['data']);
    }

    //轮巡获取短信【接口暂时不再使用】
    function getSms(){
        $order_sn = input('order_sn', '');
        $rs = ChannelCountryLogic::init()->getSms($order_sn, $this->member_id);
        if($rs['code']!=0){
            return ApiLogic::return($this->lang, $rs['code'],'',$rs['data']);
        }
        return ApiLogic::return($this->lang, 0, '', $rs['data']);
    }

    //取消收到号码的订单
    function denial(){
        $order_sn = input('order_sn', '');
        $rs = ChannelCountryLogic::init()->denial($order_sn, $this->member_id);
        if($rs['code']!=0){
            return ApiLogic::return($this->lang, $rs['code'],'',$rs['data']);
        }
        return ApiLogic::return($this->lang, 0);
    }

    //加入黑名单
    function ban(){
        $order_sn = input('order_sn', '');
        $rs = ChannelCountryLogic::init()->ban($order_sn, $this->member_id);
        if($rs['code']!=0){
            return ApiLogic::return($this->lang, $rs['code'],'',$rs['data']);
        }
        return ApiLogic::return($this->lang, 0);
    }

    //获取购买订单列表
    function getSmsList(){
        // echo $this->member_id;
        $rs = ChannelCountryLogic::init()->getSmsList($this->lang, $this->member_id, $this->exchange_rate);
        if($rs['code']!=0){
            return ApiLogic::return($this->lang, $rs['code']);
        }
        return ApiLogic::return($this->lang, 0,'', $rs['data']);
    }

    //关闭订单
    function closeOrder(){
        $order_sn = input('order_sn', '');
        $rs = ChannelCountryLogic::init()->closeOrder($order_sn, $this->member_id);
        if($rs['code']!=0){
            return ApiLogic::return($this->lang, $rs['code'],'',$rs['data']);
        }
        return ApiLogic::return($this->lang, 0);
    }

    function getSecondSmsList(){
        $rs = ChannelCountryLogic::init()->getSecondSmsList($this->lang, $this->member_id, $this->exchange_rate);
        if($rs['code']!=0){
            return ApiLogic::return($this->lang, $rs['code']);
        }
        return ApiLogic::return($this->lang, 0,'', $rs['data']);
    }

    //短信二次购买
    function buySmsSecond(){
        $rs = ChannelCountryLogic::init()->buySmsSecond($this->lang, $this->member_id);
        if($rs['code']!=0){
            $msg = isset($rs['msg'])?$rs['msg']:'';
            return ApiLogic::return($this->lang, $rs['code'], $msg);
        }
        return ApiLogic::return($this->lang, 0,'', $rs['data']);
    }


}
